var digitArray = new Array('0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f');

function toHex( n ) 
{
	var result = ''
	var start = true;

	for ( var i=32; i>0; ) 
	{
		i -= 4;
		var digit = ( n >> i ) & 0xf;

		if (!start || digit != 0) 
		{
			start = false;
			result += digitArray[digit];
		}
	}

	return ( result == '' ? '0' : result );
}

window.onload = function()
{
	try
	{
		var DevicePath,ret,n,mylen;
		if(window.ActiveXObject)
		{
			//建立操作我们的锁的控件对象，用于操作我们的锁
			var aObject = new ActiveXObject("Syunew6A.s_simnew6");
			
			if(aObject)
			{
				//查找是否存在锁,这里使用了FindPort函数
				DevicePath = aObject.FindPort(0);
			
				if(document.frmlogin)
				{
					//读取锁的唯一ID
					frmlogin.KeyID.value=toHex(aObject.GetID_1(DevicePath))+toHex(aObject.GetID_2(DevicePath));
					
					//获取设置在锁中的用户名，使用默认的读密码"FFFFFFFF","FFFFFFFF
					ret=aObject.YRead(0,1,"D3E08431","76D4BDC0",DevicePath);
					mylen =aObject.GetBuf(0);
					frmlogin.username.value=aObject.YReadString(1,mylen, "D3E08431", "76D4BDC0", DevicePath);

					//获到设置在锁中的用户密码,,使用默认的读密码"FFFFFFFF","FFFFFFFF"
					ret=aObject.YRead(20,1,"D3E08431","76D4BDC0",DevicePath);
					mylen =aObject.GetBuf(0);
					frmlogin.password.value=aObject.YReadString(21,mylen,"D3E08431", "76D4BDC0", DevicePath);

					//这里返回对随机数的HASH结果
					frmlogin.return_EncData.value=aObject.EncString(frmlogin.rnd.value,DevicePath);
				}
			}
		}
	}
	catch(e)
	{
	}
};